package com.sigmazero13.MKDummy.models;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CardDeck implements Serializable {
	
	private static final long serialVersionUID = -5441947594976492588L;
	private List<Card> drawPile = new ArrayList<Card>();
	private List<Card> discards = new ArrayList<Card>();
	
	public CardDeck() {
		for (ManaColor c : ManaColor.values()) {
			if (!c.isBasic()) continue;
			for (int i = 0; i < 4; i++) {
				discards.add(new Card(c));
			}
		}
		
		reshuffle();
	}
	
	
	public void reshuffle() {
		drawPile.addAll(discards);
		discards.clear();
		
		Collections.shuffle(drawPile);
	}
	
	public Integer countCardsRemaining() {
		return drawPile.size();
	}
	
	public Integer countCardsRemainingOfColor(ManaColor color) {
		int count = 0;
		for (Card c : drawPile) {
			if (c.getColor().equals(color)) {
				count++;
			}
		}
		return count;
	}
	
	public Boolean hasSpellOfColor(ManaColor color) {
		for (Card c : drawPile) {
			if (c.getColor().equals(color) && c.isSpell()) {
				return true;
			}
		}
		
		return false;
	}
	
	public Card drawCard() {
		if (countCardsRemaining() == 0) {
			return null;
		} else {
			Card c = drawPile.get(0);
			discards.add(c);
			drawPile.remove(0);
			return c;
		}
	}
	
	public void addNewCard(Card newCard) {
		discards.add(newCard);
	}
}
